package com.qqzone.controller;

import com.qqzone.pojo.HostReply;
import com.qqzone.pojo.Reply;
import com.qqzone.pojo.Topic;
import com.qqzone.pojo.UserBasic;
import com.qqzone.service.HostReplyService;
import com.qqzone.service.ReplyService;

import java.util.Date;
import java.util.List;

/**
 * @author Yang
 * @creat 15:42 2022/8/30
 * @sice 1.8
 */

public class HostReplyController {
    private HostReplyService hostReplyService = null;
    private ReplyService replyService = null;

    public String addHostReply(Integer replyId, String content, javax.servlet.http.HttpSession session) {

        UserBasic author = (UserBasic) session.getAttribute("userBasic");
        HostReply hostReply = new HostReply(content, new Date(), author, new Reply(replyId));
        hostReplyService.addHostReply(hostReply);

        Topic topic = (Topic) session.getAttribute("topic");

        return "redirect:topic.do?operate=topicDetail&id=" + topic.getId();
    }

    public String delHostReply(Integer replyId, javax.servlet.http.HttpSession session) {
        hostReplyService.delHostReply(replyId);
        Topic topic = (Topic) session.getAttribute("topic");

        return "redirect:topic.do?operate=topicDetail&id=" + topic.getId();
    }

    // 添加主人回复的过度，获取reply放置到request域中，再经过page.do渲染
    public String pageAddHostReply(Integer replyId, javax.servlet.http.HttpSession session){
        Reply reply = replyService.getReplyByReplyId(replyId);
        session.setAttribute("reply",reply);
        return "frames/addHostReply";
    }
}
